using UnityEngine;
using System.Collections;

public class Turret : Enemy {

    public Transform laserSpawner;
    public Transform laserPrefab;

    public override void Start()
    {
        base.Start();

        hp = 100;
        damage = 15;
        damageDelay = 2;
        damageTimer = 2;
    }

    public override void Attack()
    {
        base.Attack();

        transform.LookAt(new Vector3(player.position.x, transform.position.y, player.position.z));

        int distanceDiff = Mathf.Abs((int)gameObject.transform.position.z - (int)player.position.z);

        if (distanceDiff < 10)
        {
            Shoot();
        }
    }

    public void Shoot()
    {
        damageTimer += Time.deltaTime;

        if (damageTimer >= damageDelay)
        {
            Instantiate(laserPrefab, new Vector3(laserSpawner.transform.position.x, laserSpawner.transform.position.y, laserSpawner.transform.position.z), transform.rotation);
            damageTimer = 0;
        }
    }
}